package com.yun.controller;


import com.yun.entity.Result;
import com.yun.entity.ReturnBean;
import com.yun.service.ResultService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Result)表控制层
 *
 * @author makejava
 * @since 2021-11-27 15:56:38
 */
@RestController
@RequestMapping("result")
public class ResultController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ResultService resultService;

    /**
     * 分页查询所有数据
     *
     * @param page 页数
     * @param limit 每页显示的条数
     * @param result 查询实体
     * @return 所有数据
     */
    /*@GetMapping("selectAllByLimit")
    public ReturnBean selectAllByLimit(Integer page,Integer limit, Result result) {
        Page<Result> pageObj = new Page<>(page,limit);
        Page<Result> pageTester = resultService.page(pageObj,new QueryWrapper<>(result));
        return success(pageTester.getRecords(),pageTester.getTotal());
    }*/

    /**
     * 通过主键查询单条数据

     */
    @GetMapping("{id}")
    public ReturnBean selectOne(@PathVariable Serializable id) {
        return success(this.resultService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param answerList 实体对象
     * @return 新增结果
     */
    @PostMapping("resultSubmit")
    public ReturnBean insert(@RequestParam("answerList[]") List<String> answerList) {
        boolean save = resultService.save(answerList);
        if(save){
            return success(null,0L);
        }else{
            return fail(null);
        }
    }

    /**
     * 修改数据
     *
     * @param result 实体对象
     * @return 修改结果
     */
    @PutMapping
    public ReturnBean update(@RequestBody Result result) {
        return success(this.resultService.updateById(result));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public ReturnBean delete(@RequestParam("idList") List<Long> idList) {
        return success(this.resultService.removeByIds(idList));
    }
}

